package org.dei.dataserver;

import java.util.Iterator;

import org.dei.perla.rockfall.RockfallManager;
import org.dei.perla.rockfall.gui.MainWindow;
import org.dei.perla.sys.device.fpc.FPC;
import org.dei.perla.sys.device.fpc.dspic.DSPicFPC;
import org.dei.perla.sys.device.fpc.intec.IntecFpc;
import org.dei.perla.utils.PerlaEnv;
import org.dei.perla.utils.PerlaRuntime;

public class GuiDSPic {
	
	private static RockfallManager manager;

	public static void main(String args[]) {
		PerlaEnv.init();
		PerlaRuntime.init();

		manager = new RockfallManager();
		
		// Inizializzo l'interfaccia grafica ed aggancio le varie FPC
		javax.swing.SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				MainWindow window = new MainWindow(manager);
				window.showGui();
				
				// Aggiungo tutti i DSPic da cui voglio ricevere i dati
				Iterator<FPC> iterator = manager.getListIterator();
				int i = 0;
				while (iterator.hasNext()) {
					FPC fpc = iterator.next();
					if(i == 0){
						IntecFpc intecFpc = (IntecFpc) fpc;
						window.addIntecDevice("Intec ", intecFpc.registerQuery(null));
						i++;
					}
					else{
						DSPicFPC picFPC = (DSPicFPC) fpc;
						window.addDevice("DSPic " + i++, picFPC.registerQuery(null));					
					}
				}
			}
		});
	}
}
